<template>
	<view class="container-box">
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="(item, i) in goodsInfo.pics" :key="i">
				<image :src="item.pics_big_url" @click="preView(i)" mode="widthFix"></image>
			</swiper-item>
		</swiper>
		
		<!-- 主体价格 -->
		<view class="goods-main-text" v-if="goodsInfo.goods_name">
			<view class="goods-price">
				¥ {{goodsInfo.goods_price}}
			</view>
			<view class="goods-header-box">
				<view class="goods-title">
					{{goodsInfo.goods_name}}
				</view>
				<view class="goods-icon-box">
					<view class="goods-icon">
						<u-icon name="star" color="#d5d5d6" size="28"></u-icon>
					</view>
					<view class="goods-icon-text">
						<text>收藏</text>
					</view>
				</view>
				
			</view>
			<view class="goods-freight">
				<text>快递: &nbsp免运费</text>
			</view>
		</view>
		
		<rich-text :nodes="goodsInfo.goods_introduce"></rich-text>
		
		<view class="nav-bottom" v-if="goodsInfo.goods_name">
			<my-bottom-button :goods_info="goodsInfo"></my-bottom-button>
		</view>
	</view>
</template>

<script>
	
import { getGoodsDetail } from '@/config/api.js';
// import { mapState,mapMutations } from 'vuex'

	export default {
		data() {
			return {
				goodsInfo: {}
			}
		},
		props:{
			goodsId:{
				type:Number,
				default:0
			}
		},
		// computed:{
		// 	...mapState('m_cart', ['cart']),
		// 	...mapMutations('m_cart', ['addToCart'])
		// },
		onLoad(optins) {
			const goodsId = optins.goods_id
			this.getGoodsDetailList(goodsId)
		},
		methods:{
			toJSON(){
		
			},
			async getGoodsDetailList(id) {
				const {data:res} = await getGoodsDetail(id)
				
				//
				//使用字符串replace 替换方法，使用全局默认/g，解决图片底部空白 
				//ios设备部分不支持webp后缀图片，再正则替换
				res.message.goods_introduce = res.message.goods_introduce.replace(/<img /g, '<img style="display:block;" ')
				.replace(/webp/g, 'jpg')
				this.goodsInfo = res.message
				console.log(this.goodsInfo);
			},
			preView(i){
				// 图片预览
				uni.previewImage({
					current: i,
					urls: this.goodsInfo.pics.map( j => j.pics_big_url)
				})
			}
		}
	}
</script>

<style lang="scss">

	.container-box {
		padding-bottom: 50px;
	}
	swiper {
	 height: 750rpx;
	
	 .swiper-item,
	 image {
	   width: 100%;
	   height: 100%;
		}
	}
	.goods-main-text {
		padding: 30rpx;
		.goods-price {
			color: red;
			font-size: 22px;
		}
		.goods-header-box {
			display: flex;
			margin: 20rpx 0;
			.goods-title {
				font-size: 14px;
				flex: 7;
				padding-right: 20rpx;
				font-weight: 700;
				border-right: 1px dashed #b5b5b5;
			}
			.goods-icon-box {
				margin-left: 20rpx;
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				.goods-icon-text {
					font-size: 12px;
					opacity: 0.5;
				}
			}
		}
		.goods-freight {
			font-size: 12px;
			color: grey;
			
		}
		
	}
	.nav-bottom {
		width:100%;
		position:fixed;
		bottom:0;
	}
</style>
